﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Platform.Migrations
{
    /// <inheritdoc />
    public partial class modify_table_NamespaceConfig : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainProjectConfig_MainProjectSchemaConfig_ProjectSchemaConf~",
                table: "MainProjectConfig");

            migrationBuilder.DropTable(
                name: "MainProjectSchemaConfig");

            migrationBuilder.DropTable(
                name: "MainSTColumn");

            migrationBuilder.RenameColumn(
                name: "ProjectSchemaConfigId",
                table: "MainProjectConfig",
                newName: "NamespaceConfigId");

            migrationBuilder.RenameIndex(
                name: "IX_MainProjectConfig_ProjectSchemaConfigId",
                table: "MainProjectConfig",
                newName: "IX_MainProjectConfig_NamespaceConfigId");

            migrationBuilder.AddColumn<string>(
                name: "Contdesc",
                table: "MainStConfig",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<bool>(
                name: "DefaultFlag",
                table: "MainStConfig",
                type: "boolean",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<Guid>(
                name: "ProjectConfigId",
                table: "MainStConfig",
                type: "uuid",
                nullable: false,
                defaultValue: new Guid("00000000-0000-0000-0000-000000000000"));

            migrationBuilder.CreateTable(
                name: "EChartConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    EChartCodg = table.Column<string>(type: "text", nullable: false),
                    EChartName = table.Column<string>(type: "text", nullable: false),
                    Contdesc = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EChartConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EChartConfig_MainProjectConfig_ProjectConfigId",
                        column: x => x.ProjectConfigId,
                        principalTable: "MainProjectConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "MainNamespaceConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    NamespaceName = table.Column<string>(type: "text", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainNamespaceConfig", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainStColumnConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    StConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    SchemaJson = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainStColumnConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainStColumnConfig_MainStConfig_StConfigId",
                        column: x => x.StConfigId,
                        principalTable: "MainStConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SfConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProjectConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    SfCodg = table.Column<string>(type: "text", nullable: false),
                    SfName = table.Column<string>(type: "text", nullable: false),
                    SchemaJson = table.Column<string>(type: "text", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SfConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SfConfig_MainProjectConfig_ProjectConfigId",
                        column: x => x.ProjectConfigId,
                        principalTable: "MainProjectConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "WorkflowType",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    WorkflowTypeCodg = table.Column<string>(type: "text", nullable: false),
                    WorkflowTypeName = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WorkflowType", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WorkflowType_WorkflowType_ParentId",
                        column: x => x.ParentId,
                        principalTable: "WorkflowType",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateTable(
                name: "EChartOptionConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    EChartConfigId = table.Column<Guid>(type: "uuid", nullable: false),
                    SchemaJson = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_EChartOptionConfig", x => x.Id);
                    table.ForeignKey(
                        name: "FK_EChartOptionConfig_EChartConfig_EChartConfigId",
                        column: x => x.EChartConfigId,
                        principalTable: "EChartConfig",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "WorkflowModelAssocType",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    WorkflowModeId = table.Column<string>(type: "text", nullable: false),
                    WorkflowModelName = table.Column<string>(type: "text", nullable: false),
                    WorkflowTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WorkflowModelAssocType", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WorkflowModelAssocType_WorkflowType_WorkflowTypeId",
                        column: x => x.WorkflowTypeId,
                        principalTable: "WorkflowType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "WorkflowNode",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    WorkflowTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    WorkflowModelId = table.Column<string>(type: "text", nullable: false),
                    WorkflowNodeName = table.Column<string>(type: "text", nullable: false),
                    WorkflowNodeType = table.Column<int>(type: "integer", nullable: false),
                    WorkflowIndex = table.Column<int>(type: "integer", nullable: false),
                    Schema = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false),
                    ExtraProperties = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WorkflowNode", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WorkflowNode_WorkflowType_WorkflowTypeId",
                        column: x => x.WorkflowTypeId,
                        principalTable: "WorkflowType",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "WorkflowModelAssocNode",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    WorkflowModelId = table.Column<string>(type: "text", nullable: false),
                    WorkflowModelName = table.Column<string>(type: "text", nullable: false),
                    WorkflowNodeId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    IsDeleted = table.Column<bool>(type: "boolean", nullable: false, defaultValue: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_WorkflowModelAssocNode", x => x.Id);
                    table.ForeignKey(
                        name: "FK_WorkflowModelAssocNode_WorkflowNode_WorkflowNodeId",
                        column: x => x.WorkflowNodeId,
                        principalTable: "WorkflowNode",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainStConfig_ProjectConfigId",
                table: "MainStConfig",
                column: "ProjectConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_EChartConfig_ProjectConfigId",
                table: "EChartConfig",
                column: "ProjectConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_EChartOptionConfig_EChartConfigId",
                table: "EChartOptionConfig",
                column: "EChartConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_MainStColumnConfig_StConfigId",
                table: "MainStColumnConfig",
                column: "StConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_SfConfig_ProjectConfigId",
                table: "SfConfig",
                column: "ProjectConfigId");

            migrationBuilder.CreateIndex(
                name: "IX_WorkflowModelAssocNode_WorkflowNodeId",
                table: "WorkflowModelAssocNode",
                column: "WorkflowNodeId");

            migrationBuilder.CreateIndex(
                name: "IX_WorkflowModelAssocType_WorkflowModeId",
                table: "WorkflowModelAssocType",
                column: "WorkflowModeId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_WorkflowModelAssocType_WorkflowTypeId",
                table: "WorkflowModelAssocType",
                column: "WorkflowTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_WorkflowNode_WorkflowTypeId",
                table: "WorkflowNode",
                column: "WorkflowTypeId");

            migrationBuilder.CreateIndex(
                name: "IX_WorkflowType_ParentId",
                table: "WorkflowType",
                column: "ParentId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainProjectConfig_MainNamespaceConfig_NamespaceConfigId",
                table: "MainProjectConfig",
                column: "NamespaceConfigId",
                principalTable: "MainNamespaceConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);

            migrationBuilder.AddForeignKey(
                name: "FK_MainStConfig_MainProjectConfig_ProjectConfigId",
                table: "MainStConfig",
                column: "ProjectConfigId",
                principalTable: "MainProjectConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MainProjectConfig_MainNamespaceConfig_NamespaceConfigId",
                table: "MainProjectConfig");

            migrationBuilder.DropForeignKey(
                name: "FK_MainStConfig_MainProjectConfig_ProjectConfigId",
                table: "MainStConfig");

            migrationBuilder.DropTable(
                name: "EChartOptionConfig");

            migrationBuilder.DropTable(
                name: "MainNamespaceConfig");

            migrationBuilder.DropTable(
                name: "MainStColumnConfig");

            migrationBuilder.DropTable(
                name: "SfConfig");

            migrationBuilder.DropTable(
                name: "WorkflowModelAssocNode");

            migrationBuilder.DropTable(
                name: "WorkflowModelAssocType");

            migrationBuilder.DropTable(
                name: "EChartConfig");

            migrationBuilder.DropTable(
                name: "WorkflowNode");

            migrationBuilder.DropTable(
                name: "WorkflowType");

            migrationBuilder.DropIndex(
                name: "IX_MainStConfig_ProjectConfigId",
                table: "MainStConfig");

            migrationBuilder.DropColumn(
                name: "Contdesc",
                table: "MainStConfig");

            migrationBuilder.DropColumn(
                name: "DefaultFlag",
                table: "MainStConfig");

            migrationBuilder.DropColumn(
                name: "ProjectConfigId",
                table: "MainStConfig");

            migrationBuilder.RenameColumn(
                name: "NamespaceConfigId",
                table: "MainProjectConfig",
                newName: "ProjectSchemaConfigId");

            migrationBuilder.RenameIndex(
                name: "IX_MainProjectConfig_NamespaceConfigId",
                table: "MainProjectConfig",
                newName: "IX_MainProjectConfig_ProjectSchemaConfigId");

            migrationBuilder.CreateTable(
                name: "MainProjectSchemaConfig",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DefaultFlag = table.Column<bool>(type: "boolean", nullable: false),
                    ProjectSchemaName = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainProjectSchemaConfig", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "MainSTColumn",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    Index = table.Column<string>(type: "text", nullable: false),
                    Srtno = table.Column<int>(type: "integer", nullable: false),
                    StConfigId = table.Column<Guid>(type: "uuid", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true),
                    Title = table.Column<string>(type: "text", nullable: false),
                    Type = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_MainSTColumn", x => x.Id);
                    table.ForeignKey(
                        name: "FK_MainSTColumn_MainStConfig_StConfigId",
                        column: x => x.StConfigId,
                        principalTable: "MainStConfig",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_MainSTColumn_StConfigId",
                table: "MainSTColumn",
                column: "StConfigId");

            migrationBuilder.AddForeignKey(
                name: "FK_MainProjectConfig_MainProjectSchemaConfig_ProjectSchemaConf~",
                table: "MainProjectConfig",
                column: "ProjectSchemaConfigId",
                principalTable: "MainProjectSchemaConfig",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }
    }
}
